//
//  ANProductDetailCell.m
//  Ants
//
//  Created by ZHM on 16/3/29.
//  Copyright © 2016年 ZHM. All rights reserved.
//
#import "ANProductDetailCell.h"


@interface ANProductDetailCell ()
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *detailLabel;
@property (weak, nonatomic) IBOutlet UILabel *priceLabel;
@property (weak, nonatomic) IBOutlet UILabel *originPriceLabel;

@property (nonatomic, strong) MLEBProduct *product;

@end
@implementation ANProductDetailCell


#pragma mark- Public Methods
- (void)configureCell:(MLEBProduct *)product {
    
    NSLog(@"product====%@",product);
    self.product = product;
    self.nameLabel.text = product.title;
    self.detailLabel.text = product.intro;
    NSDecimalNumber *price = [product.price decimalNumberByDividingBy:[[NSDecimalNumber alloc] initWithInt:100]];
    NSDecimalNumber *originalPrice = [product.originalPrice decimalNumberByDividingBy:[[NSDecimalNumber alloc] initWithInt:100]];
    self.priceLabel.text = [NSString stringWithFormat:@"￥%@", price];
    NSString *originPrice = [NSString stringWithFormat:@"原价￥%@", originalPrice];
    NSAttributedString *theAttributedString;
    theAttributedString = [[NSAttributedString alloc] initWithString:originPrice attributes:@{NSStrikethroughStyleAttributeName: [NSNumber numberWithInteger:NSUnderlineStyleSingle]}];
    self.originPriceLabel.attributedText =  theAttributedString;
    
    if ([product.services count] > 0) {
        for (int i = 0; i < [product.services count]; i++) {
            UILabel *servieLabel = [self.contentView viewWithTag:i + 100];
            if (!servieLabel) {
                servieLabel = [[UILabel alloc] init];
                [self.contentView addSubview:servieLabel];
                
                servieLabel.textColor = UIColorFromRGB(0x444444);
                servieLabel.font = [UIFont systemFontOfSize:15];
                if (i == 0) {
                    //[servieLabel pinAttribute:NSLayoutAttributeLeading toAttribute:NSLayoutAttributeLeading ofItem:self.originPriceLabel];
                    servieLabel.frame = CGRectMake(self.originPriceLabel.frame.origin.x, CGRectGetMaxY(self.originPriceLabel.frame), ANscreenW, 20 * (i+1));
                } else {
                    //[servieLabel pinAttribute:NSLayoutAttributeLeading toAttribute:NSLayoutAttributeLeading ofItem:self.originPriceLabel withConstant:43];
                    //servieLabel.frame.size.height = 20;
                }
                
                //[servieLabel pinAttribute:NSLayoutAttributeTop toAttribute:NSLayoutAttributeBottom ofItem:self.originPriceLabel withConstant:10 + 28 * i];
            }
            
            if (i == 0) {
                servieLabel.text = [NSString stringWithFormat:@"服务: %@", product.services[i]];
            } else {
                servieLabel.text = product.services[i];
            }
        }
    }
    
//    if ([product.services count] > 0) {
//        self.bottomConstraint.constant = MAX(13, 13 + 28 * [product.services count]);
//    }
//    [self updateConstraints];
}

+ (instancetype)cellWithTableView:(UITableView *)tabalView {
    ANProductDetailCell *cell = [[[NSBundle mainBundle] loadNibNamed:@"ANProductDetailCell" owner:nil options:nil] firstObject]; ;
    return cell;
}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
